package com.ifcar.app.servlet;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;

/**
 * 基础服务类
 * @author ThinkPad
 *
 */
public class Base extends HttpServlet {
 
  protected static String CONTEXT_TYPE = "application/json;charset=UTF-8";
	
  protected void _401Content(HttpServletResponse resp)throws IOException {
		
		resp.setHeader("Pragma", "No-cache");
		resp.setHeader("Cache-Control", "no-cache");
		resp.setDateHeader("Expires", 0);
		resp.setCharacterEncoding("UTF-8");
		resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
		resp.getWriter().print("δ��Ȩ");
		resp.getWriter().flush();
		
	}
	
  protected void _404Content(HttpServletResponse resp)throws IOException {
		
		resp.setHeader("Pragma", "No-cache");
		resp.setHeader("Cache-Control", "no-cache");
		resp.setDateHeader("Expires", 0);
		resp.setCharacterEncoding("UTF-8");
		resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
		resp.getWriter().print("");
		resp.getWriter().flush();
		
	}
	/**
	 * @param resp
	 * @param content
	 * @throws IOException
	 */
  protected void sendContent(HttpServletResponse resp, String content, String contentType) throws IOException {

		if(null==content || "".equals(content)){
			
			_404Content(resp);
			
		}else{
			
			resp.setHeader("Pragma", "No-cache");
			resp.setHeader("Cache-Control", "no-cache");
			resp.setDateHeader("Expires", 0);
			resp.setCharacterEncoding("UTF-8");
			resp.setStatus(HttpServletResponse.SC_OK);
			resp.setContentType(contentType);
			resp.getWriter().print(content);
			resp.getWriter().flush();
		}
		
		
	}
	
}
